package vashion.azeroth.core.personal.pojo;

import com.alibaba.fastjson.JSONObject;
import vashion.azeroth.core.pojo.BaseObject;

import java.util.Date;

public class PersonalComment extends BaseObject {
    private static final long serialVersionUID = 1L;

    /**
     * 璇勮鍞竴ID
     */
    private Long cmtid;

    /**
     * 璇勮鏃堕棿
     */
    private Date ctime;

    /**
     * 璇勮鍐呭
     */
    private String content;

    /**
     * 鍥炲鐨勮瘎璁篒D锛屾病鏈変负0
     */
    private Integer replyid;

    /**
     * 鍙戝竷鑰匢D
     */
    private Long userid;

    /**
     * 鍙戝竷鑰呮樀绉�
     */
    private String nickname;

    /**
     * 鍙戝竷鑰呭ご鍍忥紙鐣欑┖浣跨敤榛樿澶村儚锛�
     */
    private String usericon;

    /**
     * 鍙戝竷鑰呬富椤靛湴鍧�锛堝彲鐣欑┖锛�
     */
    private String userurl;

    /**
     * 鍏跺畠鐢ㄦ埛鐩稿叧淇℃伅锛屼緥濡傛�у埆锛屽ご琛旂瓑鏁版嵁 - 鍦板尯
     */
    private String area;

    /**
     * 鍏跺畠鐢ㄦ埛鐩稿叧淇℃伅锛屼緥濡傛�у埆锛屽ご琛旂瓑鏁版嵁 - 鎬у埆
     */
    private String gender;

    /**
     * 鍏跺畠鐢ㄦ埛鐩稿叧淇℃伅锛屼緥濡傛�у埆锛屽ご琛旂瓑鏁版嵁 - 绛夌骇
     */
    private Integer level;

    /**
     * 鍏跺畠鐢ㄦ埛鐩稿叧淇℃伅锛屼緥濡傛�у埆锛屽ご琛旂瓑鏁版嵁 -- ip
     */
    private String ip;

    /**
     * 娴忚鍣ㄤ俊鎭�
     */
    private String useragent;

    /**
     * 1涓鸿瘎璁烘鐩存帴鍙戣〃鐨勮瘎璁猴紝2涓虹涓夋柟鍥炴祦鐨勮瘎璁�
     */
    private String channeltype;

    /**
     * 璇勮琚俯娆℃暟
     */
    private Integer opcount;

    /**
     * 1涓哄浘鐗囥��2涓鸿闊炽��3涓鸿棰�
     */
    private Integer type;

    /**
     * 闄勪欢鍦板潃
     */
    private String url;

    /**
     * 璇勮鏉ユ簮
     */
    private String cmtfrom;

    /**
     * 璇勮琚《娆℃暟
     */
    private Integer spcount;

    /**
     * 闄勪欢鎻忚堪
     */
    private String attachmentdesc;

    /**
     * 鍒涘缓鏃堕棿
     */
    private Date timeAdd;

    /**
     * 淇敼鏃堕棿
     */
    private Date timeEdit;

    /**
     * 鏂囩珷ID
     */
    private Integer sourceid;

    /**
     * 鏂囩珷鍙戝竷鑰匢D
     */
    private Integer ownerid;


    public Long getCmtid() {
        return cmtid;
    }

    public void setCmtid(Long cmtid) {
        this.cmtid = cmtid;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Integer getReplyid() {
        return replyid;
    }

    public void setReplyid(Integer replyid) {
        this.replyid = replyid;
    }

    public Long getUserid() {
		return userid;
	}

	public void setUserid(Long userid) {
		this.userid = userid;
	}

	public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getUsericon() {
        return usericon;
    }

    public void setUsericon(String usericon) {
        this.usericon = usericon;
    }

    public String getUserurl() {
        return userurl;
    }

    public void setUserurl(String userurl) {
        this.userurl = userurl;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getUseragent() {
        return useragent;
    }

    public void setUseragent(String useragent) {
        this.useragent = useragent;
    }

    public String getChanneltype() {
        return channeltype;
    }

    public void setChanneltype(String channeltype) {
        this.channeltype = channeltype;
    }

    public Integer getOpcount() {
        return opcount;
    }

    public void setOpcount(Integer opcount) {
        this.opcount = opcount;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getCmtfrom() {
        return cmtfrom;
    }

    public void setCmtfrom(String cmtfrom) {
        this.cmtfrom = cmtfrom;
    }

    public Integer getSpcount() {
        return spcount;
    }

    public void setSpcount(Integer spcount) {
        this.spcount = spcount;
    }

    public String getAttachmentdesc() {
        return attachmentdesc;
    }

    public void setAttachmentdesc(String attachmentdesc) {
        this.attachmentdesc = attachmentdesc;
    }

    public Date getTimeAdd() {
        return timeAdd;
    }

    public void setTimeAdd(Date timeAdd) {
        this.timeAdd = timeAdd;
    }

    public Date getTimeEdit() {
        return timeEdit;
    }

    public void setTimeEdit(Date timeEdit) {
        this.timeEdit = timeEdit;
    }

    public Integer getOwnerid() {
        return ownerid;
    }

    public void setOwnerid(Integer ownerid) {
        this.ownerid = ownerid;
    }

    public Integer getSourceid() {
        return sourceid;
    }

    public void setSourceid(Integer sourceid) {
        this.sourceid = sourceid;
    }

    public static PersonalComment buildFromJson(JSONObject changObject) throws Exception {

        // FIXME 鏈�澶栧眰鍙傛暟

        JSONObject commentJson = changObject.getJSONArray("comments").getJSONObject(0);
        JSONObject userJson = commentJson.getJSONObject("user");


        PersonalComment personalComment = new PersonalComment();

//        personalComment.setArea();
//        personalComment.setGender();
//        personalComment.setLevel();

        personalComment.setAttachmentdesc(commentJson.get("attachment").toString());
        personalComment.setChanneltype(commentJson.getString("channeltype"));
        personalComment.setCmtfrom(commentJson.getString("from"));

//        personalComment.setCmtid(commentJson.getInteger("cmtid"));

        personalComment.setContent(commentJson.getString("content"));
        personalComment.setCtime(new Date(commentJson.getLong("ctime")));
        personalComment.setNickname(userJson.getString("nickname"));
        personalComment.setIp(commentJson.getString("ip"));

        personalComment.setOpcount(commentJson.getInteger("opcount"));
        personalComment.setReplyid(commentJson.getInteger("replyid"));

        //FIXME sourceId鍜� ownerId 鏈夐棶棰橈紝
//        personalComment.setOwnerid();
//        personalComment.setSourceid(changObject.getLong("sourceid").intValue());
        personalComment.setSpcount(commentJson.getInteger("spcount"));

        personalComment.setTimeAdd(new Date());
        personalComment.setTimeEdit(new Date());
//        personalComment.setType();

        personalComment.setUsericon(userJson.getString("usericon"));
        personalComment.setUrl(changObject.getString("url"));
        personalComment.setUseragent(commentJson.getString("useragent"));
        personalComment.setUserid(userJson.getLong("userid"));
        personalComment.setUserurl(userJson.getString("userurl"));

        return personalComment;
    }

//    public static void main(String[] args) throws Exception {
//        String json = "{\"comments\":[{\"apptype\":40,\"attachment\":[],\"channelid\":944466,\"channeltype\":1,\"cmtid\":\"909975285\",\"content\":\"鍝堝搱鍝圽",\"ctime\":1450506675000,\"from\":0,\"ip\":\"183.159.125.68\",\"opcount\":0,\"referid\":\"909975285\",\"replyid\":\"0\",\"spcount\":0,\"user\":{\"nickname\":\"闃跨墰鍝 浜嗙埜鐖哥埜鐖哥埜鐖竆",\"sohuPlusId\":314196041,\"usericon\":\"http://vashion-item.oss-cn-hangzhou.aliyuncs.com/itemimg/20151206/1449364515.jpg\",\"userid\":\"143\",\"usermetadata\":\"\",\"userurl\":\"\"},\"useragent\":\"vashion/1 CFNetwork/711.5.6 Darwin/14.0.0\"}],\"metadata\":\"{\\\"Emotion_Neg\\\":\\\"13\\\",\\\"local_ip\\\":\\\"10.11.152.41\\\",\\\"Emotion_Pos\\\":\\\"8\\\"}\",\"sourceid\":\"4294967396\",\"ttime\":1449241432000,\"url\":\"\"}";
//        PersonalComment personalComment = PersonalComment.buildFromJson(JSONObject.parseObject(json));
//        System.out.println(personalComment);
//    }
}